"""
@FileName：3读写csv文件.py
@Author：lmz
@Time：2021/5/20 22:36
有一个名为stulist.csv的文件，请写程序读取文件内容，并打印出排名第3的学生的姓名和分数。
"""
import csv
with  open('test.csv', 'w') as csvFile:
    writer = csv.writer(csvFile)
    # 先写columns_name
    writer.writerow(["index", "name", "score"])
    # 写入多行用writerows
    writer.writerows([[1, '小明', 70], [2, '小红', 80], [3, '小黄', 90]])
# 用DictReader读取csv文件
with open('test.csv', 'r') as csvFile:
    reader = csv.DictReader(csvFile)
    for line in reader:
        if line['index'] == '3':
            print(line['name'],line['score'])